package remote.skins
{
	import flash.display.Graphics;
	
	import remote.controls.Button;
	import remote.controls.Component;
	import remote.enums.MouseStatus;
	import remote.skins.brushes.SolidBrush;
	
	
	/**
	 * 按钮皮肤
	 * @createDate 2011-3-2
	 * @author 徐俊杰
	 */
	public class ButtonSkin extends SkinBase implements ISkin
	{
		private var _out:SolidBrush = new SolidBrush(0xcccccc, 1, 0x999999, 1, 1);
		private var _over:SolidBrush = new SolidBrush(0xff0000, 1, 0xcccccc, 1, 1);
		private var _down:SolidBrush = new SolidBrush(0x999999, 1, 0x666666, 1, 1);
		
		private var _disableOut:SolidBrush = new SolidBrush(0xcccccc, 1, 0xcccccc, 1, 1);
		private var _disableOver:SolidBrush = new SolidBrush(0xcccccc, 1, 0xcccccc, 1, 1);
		private var _disableDown:SolidBrush = new SolidBrush(0xcccccc, 1, 0xcccccc, 1, 1);
		
		private var _selectOut:SolidBrush = new SolidBrush(0x999999, 1, 0xcccccc, 1, 1);
		private var _selectOver:SolidBrush = new SolidBrush(0xcccccc, 1, 0xffffff, 1, 1);
		private var _selectDown:SolidBrush = new SolidBrush(0x666666, 1, 0x999999, 1, 1);
		
		private var _selectDisableOut:SolidBrush = new SolidBrush(0x666666, 1, 0x666666, 1, 1);
		private var _selectDisableOver:SolidBrush = new SolidBrush(0x666666, 1, 0x666666, 1, 1);
		private var _selectDisableDown:SolidBrush = new SolidBrush(0x666666, 1, 0x666666, 1, 1);
		
		public function ButtonSkin()
		{
			super();
		}
		
		public function draw(target:Component):void
		{
			var brush:SolidBrush = getBrush(target);
			var g:Graphics = target.graphics;
			g.clear();
			g.lineStyle(brush.borderThickness, brush.borderColor, brush.borderAlpha, true);
			g.beginFill(brush.backgroundColor, brush.backgroundAlpha);
			g.drawRect(0, 0, target.width - brush.borderThickness, target.height -brush.borderThickness);
			g.endFill();
		}
		
		/**
		 * 获取画笔 
		 * @return 画笔 
		 * 
		 */		
		protected function getBrush(target:Component):SolidBrush
		{
			switch(target.skinStatus)
			{
				case Button.createStatusString(MouseStatus.OUT, true, false):
					return _out;
				case Button.createStatusString(MouseStatus.OVER, true, false):
					return _over;
				case Button.createStatusString(MouseStatus.DOWN, true, false):
					return _down;
				
				case Button.createStatusString(MouseStatus.OUT, false, false):
					return _disableOut;
				case Button.createStatusString(MouseStatus.OVER, false, false):
					return _disableOver;
				case Button.createStatusString(MouseStatus.DOWN, false, false):
					return _disableDown;
				
				case Button.createStatusString(MouseStatus.OUT, true, true):
					return _selectOut;
				case Button.createStatusString(MouseStatus.OVER, true, true):
					return _selectOver;
				case Button.createStatusString(MouseStatus.DOWN, true, true):
					return _selectDown;
				
				case Button.createStatusString(MouseStatus.OUT, false, true):
					return _selectDisableOut;
				case Button.createStatusString(MouseStatus.OVER, false, true):
					return _selectDisableOver;
				case Button.createStatusString(MouseStatus.DOWN, false, true):
					return _selectDisableDown;
				default:
					return _out;
			}
		}
	}
}